package com.example.practice.controller;

import com.example.practice.entity.JsonResponse;
import com.example.practice.entity.Rule;
import com.example.practice.service.RuleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/rule")
public class RuleController {
    @Resource
    RuleService ruleService;
    @GetMapping("/getRule")
    public Rule getRule(Integer aid){
        return this.ruleService.queryById(aid);
    }
    @PostMapping("/setRule")
    public JsonResponse setRule(@RequestBody Rule rule){
        this.ruleService.insert(rule);
        return JsonResponse.success("设置成功");
    }
    @ApiOperation("通过活动id查询活动rule信息")
    @GetMapping("/getRuleByAid")
    public Rule getRuleByAid(Integer aid){
        Rule rule = this.ruleService.queryByAId(aid);
        return rule;
    }
    @ApiOperation("通过活动名称联合活动表查询rule信息")
    @GetMapping("/getRuleByName")
    public Rule getRuleByName(String name){
        Rule rule = this.ruleService.queryByName(name);
        return rule;
    }
}
